<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="../common/taglibs.jspf"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><spring:message code="webapp.menu.admin.authority" /></title>
<!-- meta -->
<meta name="menu-admin" content="nav-active" />
<meta name="menu-admin-authority" content="active" />
</head>

<body>
	<div>
		<div style="padding: 5px;overflow: visible;" class="search-toolbar">
			<form id="searchForm" class="form-inline">
				<div class="form-group">
					<label for="name"><spring:message code="webapp.page.admin.authority.name" />：</label>
					<input class="form-control" id="name" name="name" style="width: 100px;"/>
				</div>
				<div class="form-group">
					<label for="displayName"><spring:message code="webapp.page.admin.authority.displayName" />：</label>
					<input class="form-control" id="displayName" name="displayName" style="width: 100px;"/>
				</div>
				<div class="form-group">
					<label for="startCreateTime"><spring:message code="webapp.page.admin.authority.createTime" />：</label>
					<input class="form-control form_datetime" name="startCreateTime" style="width:150px" />
					<em> - </em>
					<input class="form-control form_datetime" name="endCreateTime" style="width:150px" />
				</div>
				<div class="form-group">
					<label for="startUpdateTime"><spring:message code="webapp.page.admin.authority.updateTime" />：</label>
					<input class="form-control form_datetime" name="startUpdateTime" style="width:150px" />
					<em> - </em>
					<input class="form-control form_datetime" name="endUpdateTime" style="width:150px" />
				</div>
				<div class="form-group" style="float:right;">
					<button type="submit" onClick="searchSubmit();return false" id="searchBtn" href="javascript:void(0)" class="btn btn-primary"
						iconCls="icon-search"><spring:message code="webapp.constant.search" /></button>
					<a id="resetSearchBtn" href="javascript:void(0)" class="btn btn-primary"
						iconCls="icon-undo"><spring:message code="webapp.constant.resetSearch" /></a>
				</div>
			</form>
		</div>
		<div class="clear"></div>
		<div>
			<div id="toolbar" class="btn-group">
				<button id="btn_add" class="btn btn-default" data-toggle="modal" data-target="#addModal">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>

			<!-- 新增 模态框 -->
			<div class="modal fade" id="addModal" tabindex="-1" role="dialog" 
			   aria-labelledby="myModalLabel" aria-hidden="true">
			   	<div class="modal-dialog">
					<div class="modal-content">
					  <div class="modal-header">
					    <button id="addClose" type="button" class="close" 
					       data-dismiss="modal" aria-hidden="true">
					          &times;
					    </button>
					    <h4 class="modal-title" id="myModalLabel">
					       新增
					    </h4>
					  </div>
					  <div class="modal-body">
					  	<form id="addForm" class="form-horizontal" role="form">
							<div class="form-group">
								<label class="col-sm-3 control-label" for="username"><spring:message code="webapp.page.admin.authority.name" />：</label>
								<div class="col-sm-7"><input type="text" class="form-control" name="name"/></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label" for="realName"><spring:message code="webapp.page.admin.authority.displayName" />：</label>
								<div class="col-sm-7"><input type="text" class="form-control" name="displayName"/></div>
							</div>
						   <div class="form-group">
						      <div class="col-sm-offset-3 col-sm-7">
					  			<p id="addErrorInfo" class="alert alert-danger errorInfo"></p>
						      </div>
						   </div>
						</form>
					  </div>
					  <div class="modal-footer">
					    <button id="addSubmit" type="button" class="btn btn-primary">
					       提交
					    </button>
						<button type="button" class="btn btn-default" 
						data-dismiss="modal">取消
						</button>
					  </div>
					</div>
				</div>
			</div>

			<!-- 编辑 模态框 -->
			<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" 
			   aria-labelledby="myModalLabel" aria-hidden="true">
			   	<div class="modal-dialog">
					<div class="modal-content">
					  <div class="modal-header">
					    <button id="updateClose" type="button" class="close" 
					       data-dismiss="modal" aria-hidden="true">
					          &times;
					    </button>
					    <h4 class="modal-title" id="myModalLabel">
					       编辑
					    </h4>
					  </div>
					  <div class="modal-body">
					  	<form id="updateForm" class="form-horizontal" role="form">
					  		<input type="hidden" name="id">
							<div class="form-group">
								<label class="col-sm-3 control-label" for="username"><spring:message code="webapp.page.admin.authority.name" />：</label>
								<div class="col-sm-7"><input type="text" class="form-control" name="name"/></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label" for="realName"><spring:message code="webapp.page.admin.authority.displayName" />：</label>
								<div class="col-sm-7"><input type="text" class="form-control" name="displayName"/></div>
							</div>
						   <div class="form-group">
						      <div class="col-sm-offset-3 col-sm-7">
					  			<p id="updateErrorInfo" class="alert alert-danger errorInfo"></p>
						      </div>
						   </div>
						</form>
					  </div>
					  <div class="modal-footer">
					    <button id="updateSubmit" type="button" class="btn btn-primary">
					       提交
					    </button>
						<button type="button" class="btn btn-default" 
						data-dismiss="modal">取消
						</button>
					  </div>
					</div>
				</div>
			</div>

			<!-- 删除 模态框 -->
			<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" 
			   aria-labelledby="myModalLabel" aria-hidden="true">
			   	<div class="modal-dialog">
					<div class="modal-content">
					  <div class="modal-header">
					    <button type="button" class="close" 
					       data-dismiss="modal" aria-hidden="true">
					          &times;
					    </button>
					    <h4 class="modal-title" id="myModalLabel">
					       确认
					    </h4>
					  </div>
					  <div class="modal-body">
					  	<p>您确认要进行该操作？</p>
					  	<input id="deleteId" type="hidden" value="">
					  	<p id="deleteErrorInfo" class="alert alert-danger errorInfo"></p>
					  </div>
					  <div class="modal-footer">
					    <button id="deleteSubmit" type="button" class="btn btn-primary">
					       确认
					    </button>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消
						</button>
					  </div>
					</div>
				</div>
			</div>
			
            <table id="table" 
            	data-toggle="table" 
            	data-url="/opAdmin/authority/list"
            	data-pagination="true"
            	data-page-list="[5, 10, 15, 20, ALL]"
            	data-side-pagination="server"
                data-unique-id="id"
                data-query-params="paramPretreatment"
                data-query-params-type=""
            	data-show-export="true"
            	data-response-handler="dataPretreatment"
            	data-toolbar="#toolbar"
            	data-show-refresh="true" >
            	<!-- -->
				<thead>
					<tr>
						<th data-field="id" data-sortable="true"><spring:message code="webapp.page.admin.authority.id" /></th>
						<th data-field="name" data-sortable="true"><spring:message code="webapp.page.admin.authority.name" /></th>
						<th data-field="displayName" data-sortable="true"><spring:message code="webapp.page.admin.authority.displayName" /></th>
						<th data-field="createTime" data-sortable="true"><spring:message code="webapp.page.admin.authority.createTime" /></th>
						<th data-field="updateTime" data-sortable="true"><spring:message code="webapp.page.admin.authority.updateTime" /></th>
			   			<th data-field="operations" data-formatter="operationsFormatter">操作</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>

	<script type="text/javascript">
	var searchParams = new Object();
	function paramPretreatment(params) {
		searchParams.limit = params.pageSize;
		searchParams.offset = params.pageNumber;
		searchParams.order = params.sortOrder;
		searchParams.search = params.searchText;
		searchParams.sort = params.sortName;
		return searchParams;
	}
	function operationsFormatter(value,row,index) {
		return ['<button onClick="editRow(' + row.id + ')" class="btn btn-default" title="编辑"><i class="fa fa-pencil-square"></i>  编辑</button>',
		'<button onClick="deleteRow(' + row.id + ')" class="btn btn-default" title="删除"><i class="fa fa-times"></i>  删除</button>'].join(' ');
	}

	$('#addSubmit').click(function(){
		$('#addForm').ajaxSubmit({
			url:'/opAdmin/authority/add',
			type:'post',
			dataType:'json',
			success:function(res) {
				if (res.code == 0) {
					$('#addModal').modal('hide');
					$('#addForm input[type=text]').val('');
					$('#addErrorInfo').hide();
					$('#table').bootstrapTable('refresh');
				}
				else {
					$('#addErrorInfo').text(res.message);
					$('#addErrorInfo').show();
				}
			},
			error:function(msg) {
				$('#addErrorInfo').text('<spring:message code="js.msg.server.error" />');
				$('#addErrorInfo').show();						
			}
		})
	});

	function editRow(id) {
		var rowData = $('#table').bootstrapTable('getRowByUniqueId', id);
		$('#updateForm input[name=id]').val(rowData.id);
		$('#updateForm input[name=name]').val(rowData.name);
		$('#updateForm input[name=displayName]').val(rowData.displayName);

		$('#updateErrorInfo').hide();
		$('#updateModal').modal();
	}
	$('#updateSubmit').click(function(){
		$('#updateForm').ajaxSubmit({
			url:'/opAdmin/authority/update',
			type:'post',
			//data:updateData,
			dataType:'json',
			success:function(res) {
				if (res.code == 0) {
					$('#updateModal').modal('hide');
					$('#updateErrorInfo').hide();
					$('#table').bootstrapTable('refresh');
				}
				else {
					$('#updateErrorInfo').text(res.message);
					$('#updateErrorInfo').show();
				}
			},
			error:function(msg) {
				$('#updateErrorInfo').text('<spring:message code="js.msg.server.error" />');
				$('#updateErrorInfo').show();						
			}
		})
	});

	$('#deleteSubmit').click(function(){
		var deleteId = new Object();
		deleteId.id = $('#deleteModal #deleteId').val();

		$.ajax({
			url:'/opAdmin/authority/delete',
			type:'post',
			data:deleteId,
			dataType:'json',
			success:function(res) {
				if (res.code == 0) {
					$('#deleteModal').modal('hide');
					$('#deleteErrorInfo').hide();
					$('#table').bootstrapTable('removeAll');
					$('#table').bootstrapTable('refresh');
				}
				else {
					$('#deleteErrorInfo').text(res.message);
					$('#deleteErrorInfo').show();
				}
			},
			error:function(msg) {
				showSysMsg(1,'<spring:message code="js.msg.server.error" />');
			}
		});
	});

	function searchSubmit(){
		var searchData = new Object();
		$('#searchForm input[name=id]').val()=='' ? (searchParams.id = null) : (searchParams.id = searchData.id = $('#searchForm input[name=id]').val());
		$('#searchForm input[name=name]').val()=='' ? (searchParams.name = null) : (searchParams.name = searchData.name = $('#searchForm input[name=name]').val());
		$('#searchForm input[name=displayName]').val()=='' ? (searchParams.displayName = null) : (searchParams.displayName = searchData.displayName = $('#searchForm input[name=displayName]').val());
		$('#searchForm input[name=startCreateTime]').val()=='' ? (searchParams.startCreateTime = null) : (searchParams.startCreateTime = searchData.startCreateTime = $('#searchForm input[name=startCreateTime]').val());
		$('#searchForm input[name=endCreateTime]').val()=='' ? (searchParams.endCreateTime = null) : (searchParams.endCreateTime = searchData.endCreateTime = $('#searchForm input[name=endCreateTime]').val());
		$('#searchForm input[name=startUpdateTime]').val()=='' ? (searchParams.startUpdateTime = null) : (searchParams.startUpdateTime = searchData.startUpdateTime = $('#searchForm input[name=startUpdateTime]').val());
		$('#searchForm input[name=endUpdateTime]').val()=='' ? (searchParams.endUpdateTime = null) : (searchParams.endUpdateTime = searchData.endUpdateTime = $('#searchForm input[name=endUpdateTime]').val());

		searchData.limit = $('#table').bootstrapTable('getOptions').pageSize;
		searchData.offset = $('#table').bootstrapTable('getOptions').pageNumber-1;

		$.ajax({
			url:'/opAdmin/authority/list',
			type:'post',
			data:searchData,
			dataType:'json',
			success:function(res) {
				if (res.code == 0) {
					$('#table').bootstrapTable('removeAll');
					$('#table').bootstrapTable('load',res.data);
				}
			},
			error:function(msg) {
				showSysMsg(1,'<spring:message code="js.msg.server.error" />');					
			}
		});
	}
	$('#resetSearchBtn').click(function(){
		searchParams = {};
		$('#searchForm input').val('');
		$('#searchForm select').val('');
		$('#table').bootstrapTable('removeAll');
		$('#table').bootstrapTable('refresh');
	});
	$(".form_datetime").datetimepicker({format: 'yyyy-mm-dd hh:ii'});
	</script>
</body>
</html>

